<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <title>Index</title>
    <script src="/javascripts/socket.io/socket.io.js"></script>
</head>
<body>
Hello World
<button onclick="send()">say hi</button>
<button onclick="joinRoom()">JoinRoom</button>
<button onclick="leaveRoom()">LeaveRoom</button>
<button onclick="sendRoom()"> Room1-> say Hello</button>

<script>
    var socket = io("http://192.168.1.65:9095",{
        reconnectionDelay:2000
    });
    socket.on('connect', function () {
        console.info('connect netty-socket.io')
    });

    socket.on('message', function (data) {
        console.info(data)
    });

    socket.on('disconnect', function () {
        console.info('disconnect netty-socket.io')
    });

    socket.on('error', function () {
        console.error('error')
    });

    function joinRoom() {
        socket.emit('join_room',"room1",function(data){
            console.log(data);
        });
    }

    function leaveRoom() {
        socket.emit('leave_room',"room1", function (data) {
            console.log(data);
        });
    }

    function send() {
        var chatObject = {userName: 'lixuwei', message: 'hi everyone!'};
        socket.emit('message', chatObject);
    }

    function sendRoom() {
        socket.emit('room_message', "I am ok");
    }

    socket.on('room_message', function (data) {
        console.log("room_message: " + data)
    })
</script>
</body>
</html>